package com.itheima.app.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.SettingManager;
import com.itheima.app.manager.UserManager;
import com.itheima.domain.db.Notification;
import com.itheima.domain.db.User;
import com.itheima.domain.db.UserInfo;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zsk
 * @create 2022-03-14-19:44
 */
@RestController
public class SettingController {

    @Autowired
    private SettingManager settingManager;

    @Autowired
    private UserManager userManager;

    //查询通用设置
    @GetMapping("/users/settings")
    public ResponseEntity settings(){
        //调用manager
        return settingManager.settings();
    }

    //修改手机号发送短信验证码
    @PostMapping("/users/phone/sendVerificationCode")
    public void sendSms(){

        //通过ThreadLocal获取现在登录的phone
        User user = UserHolder.get();

        //调用userManager中已实现的发送验证码功能
        userManager.sendSms(user.getMobile());
    }

    //校验验证码
    @PostMapping("/users/phone/checkVerificationCode")
    public ResponseEntity checkSendSms(@RequestBody Map<String,String> param){

        //从现有令牌中获取手机号
        User user = UserHolder.get();
        String mobile = user.getMobile();

        //获取发送的验证码
        String verificationCode = param.get("verificationCode");
        //调用manager
        return settingManager.checkSendSms(verificationCode,mobile);
    }

    //修改手机号
    @PostMapping("/users/phone")
    public void updatePhone(@RequestBody Map<String,String> map ){

        //调用manager
        String phone = map.get("phone");

        settingManager.updatePhone(phone);

    }

    //设置陌生人问题
    @PostMapping("/users/questions")
    public void setQuestion(@RequestBody Map<String,String> map){

        //接收参数
        String content = map.get("content");
        //调用manager
        settingManager.setQuestion(content);
    }

    //通知设置
    @PostMapping("/users/notifications/setting")
    public void setNotification(@RequestBody Notification notificationParam){
        //调用manager
        settingManager.setNotification(notificationParam);

    }

    //分页显示黑名单
    @GetMapping("/users/blacklist")
    public ResponseEntity findBlackListByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize
    ){
        //调用manager
        return settingManager.findBlackListByPage(pageNum,pageSize);
    }

    //删除黑名单中信息
    @DeleteMapping("/users/blacklist/{blackId}")
    public void deleteById(@PathVariable Long blackId){
        //调用manager
        settingManager.deleteById(blackId);
    }


}
